<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left"><Breadcrumb /></div>
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <SearchBar :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          v-if="tableColumns.length>0"
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"
          style="width: 99.9%"
        >
          <Column v-for="(column,index) in tableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />

          <el-table-column label="操作" align="center" fixed="right" width="220">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click.stop="downloadFile(scope.row)"
              >下载</el-button>
              <el-button
                type="text"
                @click.stop="sendFile(scope.row)"
              >下发文件</el-button>
              <el-button
                type="text"
                @click.stop="sendRecord(scope.row)"
              >下发记录</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import { list } from '@/api/superManage/iotManage/iotUpload'
import { download } from '@/api/common/common'
import SendRecord from './sendRecord'
import SendFile from './sendFile'
import AddOrUpdate from './addOrUpdate'
export default {
  name: 'Index',
  data() {
    return {
      loading: true,
      pageId: '上传数据', // 页面唯一标识
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'realFileName', label: '文件名' },
        { prop: 'fileVersion', label: '版本号' },
        { prop: 'fileSize', label: '文件大小' }
      ],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        { prop: 'realFileName', label: '文件名', type: 'input' },
        { prop: 'fileVersion', label: '版本号', type: 'input' }
      ],

      operationData: [ // 右上角的操作按钮
        { label: '新增', perm: '' },
        { label: '页面配置', perm: '' }
      ]

    }
  },
  mounted() {
  },
  methods: {
    getList() {
      list(this.pageData).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
          this.tableHeight = this.$refs.table_container.offsetHeight
        })
      })
    },
    add() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {}// props
        },
        area: ['440px', '400px'],
        title: '新增文件', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    downloadFile(row) {
      download(row.fileName).then(res => {
        fetch(res.data)
          .then(response => response.blob())
          .then(res => {
            const FileSaver = require('file-saver')
            FileSaver.saveAs(res, row.realFileName)
          })
      })
    },
    sendFile(row) {
      this.$layer.iframe({// 弹框
        content: {
          content: SendFile, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            row: row
          }// props
        },
        area: ['1200px', '600px'],
        title: '下发文件', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    sendRecord(row) {
      this.$layer.iframe({// 弹框
        content: {
          content: SendRecord, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            row: row
          }// props
        },
        area: ['1200px', '600px'],
        title: '下发记录', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>
